// Copyright (c) 2019 Presto Labs Pte. Ltd.
// Author: chensili

#pragma once

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "coin2/exchange/base/symbology/spot_product.h"
#include "coin2/exchange/base/symbology/util.h"
#include "coin2/exchange/upbit_id/symbology/currency.h"
#include "coin2/exchange/upbit/symbology/product_util.h"

namespace coin2::exchange::upbit_id::symbology {

using namespace coin2::exchange::upbit::symbology::util;

class UpbitIdProduct
    : public base::symbology::SpotProduct<UpbitIdCurrency, UpbitIdProduct>,
      public base::symbology::ProductFromStrMixin<UpbitIdProduct> {
 public:
  typedef SpotProduct<UpbitIdCurrency, UpbitIdProduct> BaseProduct;

  UpbitIdProduct(
      const UpbitIdCurrency& base,
      const UpbitIdCurrency& quote) :
    SpotProduct(
        base,
        quote,
        ToUpbitNativeProduct(base, quote),
        ToUpbitNativeProduct(base, quote),
        base::market::ExchangeType::Upbitid) { }

 public:
  static std::unique_ptr<UpbitIdProduct> FromNativeStrImpl(
      const std::string& native_product,
      int64_t resolve_timestamp) {
    std::unique_ptr<UpbitIdCurrency> base_ptr;
    std::unique_ptr<UpbitIdCurrency> quote_ptr;
    bool success = ParseUpbitNativeProduct(
        native_product, resolve_timestamp, &base_ptr, &quote_ptr);
    if (success) {
      return std::make_unique<UpbitIdProduct>(*base_ptr, *quote_ptr);
    } else {
      return { };
    }
  }
};

}  // namespace coin2::exchange::upbit_id::symbology
